<?php

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Support\Facades\Route;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__ . '/../routes/web.php',
        commands: __DIR__ . '/../routes/console.php',
        api: __DIR__ . '/../routes/api.php',
        health: '/up',
        apiPrefix: defined('WP_LARA_PRESS_API_PREFIX') ? WP_LARA_PRESS_API_PREFIX : 'api',
    )
    ->withMiddleware(function (Middleware $middleware): void {
        // 替换Laravel默认的Session中间件为我们的WordPress兼容实现
        $middleware->web(remove: [
            \Illuminate\Session\Middleware\StartSession::class,
            \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        ]);

        // 添加我们的WordPress Session中间件
        $middleware->web(prepend: [
            \App\Http\Middleware\InitializeWordPressSession::class,
        ]);

        // 从API中间件组移除默认session中间件
        $middleware->api(remove: [
            \Illuminate\Session\Middleware\StartSession::class,
        ]);
    })
    ->withExceptions(function (Exceptions $exceptions): void {
        //
    })->create();
